package com.snb.play.dwebtoon.data;

import java.util.ArrayList;
import java.util.Iterator;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class DTO_EpisodeDatas extends JSonDataObjectBase {

	/**
	 * 
	 */
	private static final long serialVersionUID = 135930351L;
	public String webtoonTotalCount;
	public String id;
	public ArrayList<DTO_Episode> webtoonEpisodes;

	public DTO_EpisodeDatas() {
		super();
	}

	public DTO_EpisodeDatas(JSONObject aJsonObject, String aId) {
		@SuppressWarnings("unchecked")
		Iterator<Object> iterator = aJsonObject.keys();
		this.id = aId;
		while (iterator.hasNext()) {
			Object obj = iterator.next();
			if (obj.toString().equalsIgnoreCase("webtoonEpisodes")) {
				this.webtoonEpisodes = new ArrayList<DTO_Episode>();
				DTO_Episode lCartoon_Episode = null;
				try {

					JSONArray lartists = aJsonObject.getJSONArray("webtoonEpisodes");

					for (int i = 0; i < lartists.length(); i++) {
						lCartoon_Episode = new DTO_Episode(lartists.getJSONObject(i));
						lCartoon_Episode.pid = this.id;
						lCartoon_Episode.insertObjToDB();
						this.webtoonEpisodes.add(lCartoon_Episode);
					}

				} catch (JSONException e) {
					if (isDebug)
						e.printStackTrace();
				}

			} else {
				setMemberFiled(this, aJsonObject, obj.toString());
			}
		}

		printMembers();
	}

}
